﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using School.Entities;
using System.Data;
using System.Collections;

namespace School.Service
{

    public static class Bus
    {
        private class Buses
        {
            public long ID { get; set; }
            public string Name { get; set; }
        }

        private static SchoolEntities db = new SchoolEntities();

        public static IEnumerable<ORG_Campus> GetAllCampuses()
        {
            var result = from c in db.ORG_Campus
                         orderby c.Name
                         select c;
            return result;
        }
        public static bool AddRegion(int Campus_Id, string Dis_Code, string Name)
        {
            try
            {
                LU_District District = new LU_District();
                District.Campus_Id = Campus_Id;
                District.Dis_Code = Dis_Code;
                District.Name = Name;
                db.AddToLU_District(District);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static object GetAllDistrict()
        {
            var query = from Camp in db.ORG_Campus
                        join Distr in db.LU_District
                        on Camp.Id equals Distr.Campus_Id
                        select new
                        {

                            Camp.Name,
                            DistName = Distr.Name,
                            Distr.Dis_Code,
                            Distr.Id
                        };
            return query;
        }
        public static IEnumerable<LU_District> GetDistrict()
        {
            return (from Distr in db.LU_District select Distr);
        }
        public static bool DeleteDistrict(int Id)
        {
            var deletequery = (from distr in db.LU_District
                               where distr.Id == Id
                               select distr).Single();
            try
            {
                db.DeleteObject(deletequery);
                db.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }
        public static bool UpdateDistrict(int Id, string Dis_Code, string Name)
        {
            var Update = (from distr in db.LU_District
                          where distr.Id == Id
                          select distr).Single();
            Update.Name = Name;
            Update.Dis_Code = Dis_Code;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }


        public static bool AddStation(int Campus_Id, int District_Id, string Sta_Code, string Name)
        {
            try
            {
                SRV_Bus_Station Station = new SRV_Bus_Station();
                Station.Campus_Id = Campus_Id;
                Station.District_Id = District_Id;
                Station.Name = Name;
                Station.Sta_Code = Sta_Code;
                db.AddToSRV_Bus_Station(Station);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static object GetStation()
        {
            var query = (from st in db.SRV_Bus_Station
                         join Distr in db.LU_District
                         on st.District_Id equals Distr.Id
                         join camp in db.ORG_Campus on st.Campus_Id equals camp.Id
                         select new
                         {
                             camp.Name,
                             DistName = Distr.Name,
                             staName = st.Name,
                             st.Sta_Code,
                             st.District_Id,
                             st.Id
                         }).ToList();

            return query;
        }
        public static IEnumerable<SRV_Bus_Station> GetStationtogrid()
        {
            var query = (from st in db.SRV_Bus_Station

                         select st);
            return query;
        }
        public static bool DeleteStation(int Id)
        {
            var deletequery = (from st in db.SRV_Bus_Station
                               where st.Id == Id
                               select st).Single();
            try
            {
                db.DeleteObject(deletequery);
                db.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }
        public static bool UpdateStation(int Id, string Sta_Code, string Name)
        {
            var Update = (from st in db.SRV_Bus_Station
                          where st.Id == Id
                          select st).Single();
            Update.Name = Name;
            Update.Sta_Code = Sta_Code;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static bool AddBus(int Campus_Id, string bus_Code, string Name, int Passengers, string note)
        {
            try
            {
                SRV_Bus Bus = new SRV_Bus();
                // Bus.Id = Convert.ToInt32(bus_Code);
                Bus.Campus_Id = Campus_Id;
                Bus.Bus_Code = bus_Code;
                Bus.Name = Name;
                Bus.note = note;
                Bus.Passenger_number = Passengers;
                db.AddToSRV_Bus(Bus);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static object Getbuses()
        {
            var query = (from b in db.SRV_Bus
                         join camp in db.ORG_Campus on b.Campus_Id equals camp.Id
                         select new
                         {
                             camp.Name,
                             busname = b.Name,
                             b.Bus_Code,
                             b.note,
                             b.Passenger_number,
                             b.Id
                         }).ToList();
            return query;
        }
        public static int GetPassenger_numberById(int bid)
        {
            IEnumerable<SRV_Bus> query = (from b in db.SRV_Bus where b.Id == bid select b);
            return query.FirstOrDefault().Passenger_number;
        }
        public static bool Deletebus(int Id)
        {
            var deletequery = (from b in db.SRV_Bus
                               where b.Id == Id
                               select b).Single();
            try
            {
                db.DeleteObject(deletequery);
                db.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }
        public static bool Updatebus(int Id, string bus_Code, string Name, int Passengers, string note)
        {
            var Update = (from b in db.SRV_Bus
                          where b.Id == Id
                          select b).Single();
            Update.Name = Name;
            Update.Bus_Code = bus_Code;
            Update.Passenger_number = Passengers;
            Update.note = note;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static IEnumerable<SRV_Bus> GetBusByCamp(long campus_id)
        {
            return (from d in db.SRV_Bus where d.Campus_Id == campus_id orderby d.Name select d);
        }

        public static IEnumerable<SRV_Bus_cycle> GetCycle()
        {
            return (from c in db.SRV_Bus_cycle orderby c.Name select c);
        }
        public static IEnumerable<SRV_Bus_Station> GetstationByDistrict(long campus_id, long District_id)
        {
            return (from d in db.SRV_Bus_Station where d.Campus_Id == campus_id && d.District_Id == District_id && !(db.SRV_Bus_Station_Price.Any(c => c.Station_Id == d.Id)) orderby d.Name select d);
        }
        public static IEnumerable<SRV_Bus_Station> GetstationBy(long campus_id, long District_id)
        {
            return (from d in db.SRV_Bus_Station where d.Campus_Id == campus_id && d.District_Id == District_id orderby d.Name select d);
        }
        public static IEnumerable<SRV_Bus_Station> GetstationdllBy(long District_id)
        {
            return (from d in db.SRV_Bus_Station_Price where d.District_Id == District_id select d.SRV_Bus_Station).Distinct();
        }
        public static bool AddBus_Station_Price(int Campus_Id, int Station_Id, int Bus_Id, int Cycle_Id, int District_Id, Decimal Price)
        {
            try
            {
                SRV_Bus_Station_Price Bus = new SRV_Bus_Station_Price();
                Bus.Bus_Id = Bus_Id;
                Bus.Campus_Id = Campus_Id;
                Bus.Cycle_Id = Cycle_Id;
                Bus.District_Id = District_Id;
                Bus.Price = Price;
                Bus.Station_Id = Station_Id;
                db.AddToSRV_Bus_Station_Price(Bus);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static object GetstationPrice(long campus_id, long District_id)
        {
            return (from d in db.SRV_Bus_Station_Price
                    join s in db.SRV_Bus_Station on d.Station_Id equals s.Id
                    where d.Campus_Id == campus_id && d.District_Id == District_id
                    select new
                    {
                        d.Station_Id,
                        d.Price,
                        d.Id,
                        s.Name
                    }
                ).ToList();
        }
        public static IEnumerable<SRV_Bus_Station> GetStationByCamp(long campus_id, long bus_id)
        {
            return (from d in db.SRV_Bus_Station where d.Campus_Id == campus_id && !(db.SRV_Bus_Station_Price.Any(c => c.Station_Id == d.Id && c.Bus_Id == bus_id)) orderby d.Id select d);
        }
        //public static IEnumerable<SRV_Bus_Station> GetStationByCamp(long campus_id, long bus_id)
        //{
        //    return (from d in db.SRV_Bus_Station where  d.Campus_Id == campus_id && !(db.SRV_Bus_Station_Price.Any(c => c.Station_Id == d.Id)) orderby d.Name select d);
        //}
        public static IEnumerable<SRV_Bus_Station_Price> GetstationPricebycamp(long campus_id, long bus_id)
        {
            return (from d in db.SRV_Bus_Station_Price
                    join s in db.SRV_Bus_Station on d.Station_Id equals s.Id
                    where d.Campus_Id == campus_id && d.Bus_Id == bus_id
                    orderby s.Id
                    select d
                ).ToList();
        }
        public static bool DeleteStationprice(int Id)
        {
            var deletequery = (from b in db.SRV_Bus_Station_Price
                               where b.Id == Id
                               select b).Single();
            try
            {
                db.DeleteObject(deletequery);
                db.SaveChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }

        }
        public static bool UpdateStationPrice(int Id, Decimal price)
        {
            var Update = (from b in db.SRV_Bus_Station_Price
                          where b.Id == Id
                          select b).Single();
            Update.Price = price;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static IEnumerable<ORG_Certificate> GetCertificateByCamp(long campus_id)
        {
            return (from d in db.ORG_Certificate where d.Campus_Id == campus_id orderby d.Name select d);
        }
        public static IEnumerable<ORG_Stage> GetStageByCerti(long Certificate_Id)
        {
            return (from d in db.ORG_Stage where d.Certificate_Id == Certificate_Id orderby d.Code select d);
        }
        public static bool UpdateDiscount(int Id, float discount)
        {
            var Update = (from d in db.SRV_Bus_Price_Discount
                          where d.Id == Id
                          select d).Single();
            Update.Discount = discount;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static IEnumerable<SRV_Bus_Price_Discount> GetPrice_Discount()
        {
            return (from d in db.SRV_Bus_Price_Discount select d);
        }
        public static IEnumerable<SRV_Bus_Price_Discount> GetPrice_DiscountByid(int id)
        {
            return (from d in db.SRV_Bus_Price_Discount where d.Id == id select d);
        }
        public static bool AddPrice_Increase(int Campus_Id, int Certificate_Id, int Stage_Id, decimal Increase_Value, float Increase_percent, decimal Grade_Increase_Value, float Grade_Increase_Percent)
        {
            try
            {
                SRV_Bus_Price_Increase price = new SRV_Bus_Price_Increase();
                price.Campus_Id = Campus_Id;
                price.Certificate_Id = Certificate_Id;
                price.Stage_Id = Stage_Id;
                price.Increase_Value = Increase_Value;
                price.Increase_percent = Increase_percent;
                price.Grade_Increase_Value = Grade_Increase_Value;
                price.Grade_Increase_Percent = Grade_Increase_Percent;
                db.AddToSRV_Bus_Price_Increase(price);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static bool UpdatePrice_Increase(int Id, int cam_id, int cert_id, decimal Increase_Value, float Increase_percent, decimal Grade_Increase_Value, float Grade_Increase_Percent)
        {
            var Update = (from d in db.SRV_Bus_Price_Increase
                          where d.Stage_Id == Id && d.Campus_Id == cam_id && d.Certificate_Id == cert_id
                          select d).Single();
            Update.Increase_Value = Increase_Value;
            Update.Increase_percent = Increase_percent;
            Update.Grade_Increase_Value = Grade_Increase_Value;
            Update.Grade_Increase_Percent = Grade_Increase_Percent;
            try
            {
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static IEnumerable<SRV_Bus_Price_Increase> GetPrice_Increase(int Campus_Id, int Certificate_Id, int Stage_Id)
        {
            return (from d in db.SRV_Bus_Price_Increase where d.Campus_Id == Campus_Id && d.Certificate_Id == Certificate_Id && d.Stage_Id == Stage_Id select d);
        }
        public static IEnumerable<TE_Student> GetStudentByGrade(int Grade_ID)
        {
            var query = from Grade in db.TE_Student select Grade;
            return query.ToList().Where(s => s.Grade_ID == Grade_ID);
        }
        public static IEnumerable<object> AllFullName(int campId, int cerId, int stageId, int gradeId)
        {
            var query = from student in db.TE_Student
                        where student.Certificate_Id == cerId && student.Stage_Id == stageId
                        && student.Grade_ID == gradeId && student.Campus_Id == campId
                        select new
                        {
                            Id = student.Id,
                            FullName = student.Ar_FirstName + " " + student.Ar_SecondName + " " + student.Ar_ThirdNmae + " " + student.Ar_FourthName
                        };

            return query.ToList();
        }
        public static IEnumerable<object> AllFullName_BUS_student(int campId, int cerId, int stageId, int gradeId)
        {
            var query = from student in db.TE_Student
                        where student.Certificate_Id == cerId && student.Stage_Id == stageId
                        && student.Grade_ID == gradeId && student.Campus_Id == campId && (db.SRV_Bus_Payment_Order.Any(a => a.Student_Id == student.Id))//
                        select new
                        {
                            Id = student.Id,
                            FullName = student.Ar_FirstName + " " + student.Ar_SecondName + " " + student.Ar_ThirdNmae + " " + student.Ar_FourthName
                        };
            return query.ToList();
        }
        public static IEnumerable<object> AllFullName_Notinbus(int campId, int cerId, int stageId, int gradeId)
        {
            var query = from student in db.TE_Student
                        where student.Certificate_Id == cerId && student.Stage_Id == stageId

                        && student.Grade_ID == gradeId && student.Campus_Id == campId// && !(db.SRV_BUS_Student.Any(a => a.Student_Id == student.Id))
                        orderby student.Gender_Id, student.Ar_FirstName, student.Ar_SecondName,student.Ar_ThirdNmae, student.Ar_FourthName
                        select new
                        {
                            Id = student.Id,
                            FullName = student.Ar_FirstName + " " + student.Ar_SecondName + " " + student.Ar_ThirdNmae + " " + student.Ar_FourthName,
                        };
            //var queryYeae = from y in db.ORG_EductionalYear where y.IsCurrent == true select y;
            //int start, Endyear;
            //if (DateTime.Now.Month >= queryYeae.FirstOrDefault().StartDate.Month)
            //{
            //    start = DateTime.Now.Year;
            //    Endyear = DateTime.Now.Year + 1;
            //}
            //else
            //{
            //    start = DateTime.Now.Year - 1;
            //    Endyear = DateTime.Now.Year;
            //}
            //query = from q in query where !(db.SRV_Bus_Payment_Order.Any(s => s.Student_Id == q.Id && s.ORG_EductionalYear.EndDate.Year == Endyear && s.ORG_EductionalYear.StartDate.Year == start)) select q;
            return query.ToList();
        }
        public static IEnumerable<object> AllFullName_temp(int campId, int cerId, int stageId, int gradeId)
        {
            var query = from student in db.TE_Student
                        where student.Certificate_Id == cerId && student.Stage_Id == stageId
                        && student.Grade_ID == gradeId && student.Campus_Id == campId && (db.SRV_BUS_Student.Any(a => a.Student_Id == student.Id))
                        select new
                        {
                            Id = student.Id,
                            FullName = student.Ar_FirstName + " " + student.Ar_SecondName + " " + student.Ar_ThirdNmae + " " + student.Ar_FourthName
                        };
            query = from q in query where !(db.SRV_BUS_Student_Temp.Any(s => s.Student_Id == q.Id)) select q;
            return query.ToList();
        }
        public static IEnumerable<SRV_Bus_Station_Price> GetBusDist(int Bus_Id)
        {
            return (from d in db.SRV_Bus_Station_Price where d.Bus_Id == Bus_Id select d
                ).Distinct();
        }
        public static IEnumerable<LU_District> GetBusDistforddl(int Bus_Id)
        {
            return (from d in db.SRV_Bus_Station_Price select d.LU_District
                ).Distinct();
        }
        public static IEnumerable<SRV_Bus_Station_Price> GetStation_Price(int Bus_Id, int District_Id, int Station_Id)
        {
            return (from d in db.SRV_Bus_Station_Price where d.Bus_Id == Bus_Id && d.District_Id == District_Id && d.Station_Id == Station_Id select d);
        }
        public static IEnumerable<TE_Student> GetStudentById(int Sid)
        {

            return (from s in db.TE_Student where s.Id == Sid select s);
        }
        public static IEnumerable<SRV_Bus> GetBusbyid(int Bus_Id)
        {
            return (from d in db.SRV_Bus where d.Id == Bus_Id select d);
        }


        public static IEnumerable<ACC_Discount> getdiscountbus(string filename)
        {
            IEnumerable<SEC_Screen> sec = (from s in db.SEC_Screen where s.Name == filename select s);
            IEnumerable<ACC_Expenses_Screens> Expenses_Screens = (from e in db.ACC_Expenses_Screens where e.Screen_Id == sec.First().Id select e);
            return (from d in db.ACC_Discount
                    where d.ACC_Expense_Discount.All(s => s.Expense_Id == Expenses_Screens.First().Expense_Id)
                    select d);
        }
        public static IEnumerable<SRV_Bus> GetBus()
        {
            return (from d in db.SRV_Bus orderby d.Name select d);
        }
        public static IEnumerable<LU_Jobs> getfatherjob(int student_id)
        {
            return (from j in db.LU_Jobs where j.Id == (from f in db.SD_Father where f.Student_Id == student_id select f.job_Id).FirstOrDefault() select j);
        }
        public static IEnumerable<LU_Jobs> getmotherjob(int student_id)
        {
            return (from j in db.LU_Jobs where j.Id == (from f in db.SD_Mother where f.Student_Id == student_id select f.job_Id).FirstOrDefault() select j);
        }
        public static IEnumerable<SD_ParentsSocialStatus> getfatherStatus(int student_id)
        {
            return (from j in db.SD_ParentsSocialStatus where j.Id == (from f in db.SD_Father where f.Student_Id == student_id select f.Status_Id).FirstOrDefault() select j);
        }
        public static IEnumerable<SD_ParentsSocialStatus> getmotherStatus(int student_id)
        {
            return (from j in db.SD_ParentsSocialStatus where j.Id == (from f in db.SD_Mother where f.Student_Id == student_id select f.Status_Id).FirstOrDefault() select j);
        }
        public static long Education_Yearid()
        {

            var id = from y in db.ORG_EductionalYear where y.IsCurrent == true select y;
            return id.FirstOrDefault().Id;
        }

        public static long AddPayment_Order(int student_Id, long Payment_order_num, int? Bus_Go_Id, int? Station_Go_Id, int? Bus_Return_Id, int? Station_Return_Id, int? Price_Discout_Id, decimal value, long EDY_Id)
        {
            try
            {
                SRV_Bus_Payment_Order order = new SRV_Bus_Payment_Order();
                order.Bus_Go_Id = Bus_Go_Id;
                order.Payment_order_num = Payment_order_num;
                order.Bus_Price_Discount_Id = Price_Discout_Id;
                order.Bus_Return_Id = Bus_Return_Id;
                order.Station_Go_Id = Station_Go_Id;
                order.Station_Return_Id = Station_Return_Id;
                order.Student_Id = student_Id;
                order.Value = value;
                order.EDY_Id = EDY_Id;
                order.Date = DateTime.Now;
                db.AddToSRV_Bus_Payment_Order(order);
                db.SaveChanges();
                long id = order.Id;
                return id;
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public static bool AddPayment_ORDER_Discount(long Payment_order_Id, int Discount_Id, byte type, decimal value)
        {
            try
            {
                SRV_BUS_PAYMENT_ORDER_Discounts order = new SRV_BUS_PAYMENT_ORDER_Discounts();
                order.Payment_order_Id = Payment_order_Id;
                order.Discount_Id = Discount_Id;
                order.Type = type;
                order.value = value;
                db.AddToSRV_BUS_PAYMENT_ORDER_Discounts(order);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static IEnumerable<SRV_Bus_Payment_Order> Getorder(int st_id)
        {
            return (from o in db.SRV_Bus_Payment_Order where o.Student_Id == st_id select o);

        }

        public static IEnumerable<ACC_Voucher> GetVoucher_Id(int Expense_Id)
        {
            var q = from o in db.ACC_Voucher
                    where o.Expense_Id == Expense_Id
                        && o.ORG_EductionalYear.IsCurrent == true
                    //  && !(db.SRV_BUS_Student.Any(c => c.Voucher_Id == o.Number))
                    select o;
            return q;
        }
        public static bool Addstudent_to_bus(int student_Id, int? Bus_Go_Id, int? Station_Go_Id, int? Bus_Return_Id, int? Station_Return_Id, int Voucher_Id, int Payment_order_num)
        {
            try
            {

                SRV_BUS_Student Host = new SRV_BUS_Student();
                Host.Student_Id = student_Id;
                Host.Bus_Go_Id = Bus_Go_Id;
                Host.Station_Go_Id = Station_Go_Id;
                Host.Station_Return_Id = Station_Return_Id;
                Host.Bus_Return_Id = Bus_Return_Id;
                Host.Date = DateTime.Now;
                Host.Payment_order_num = Payment_order_num;
                Host.Voucher_Id = Voucher_Id;
                db.AddToSRV_BUS_Student(Host);
                if (Bus_Go_Id == Bus_Return_Id)
                {
                    var Update = (from c in db.SRV_Bus where c.Id == Bus_Go_Id select c).SingleOrDefault();
                    Update.Passenger_number -= 1;
                }
                else if (Bus_Go_Id != null && Bus_Return_Id != null)
                {
                    var Update = (from c in db.SRV_Bus where c.Id == Bus_Go_Id select c).SingleOrDefault();
                    Update.Passenger_number -= 1;
                    var Upd = (from c in db.SRV_Bus where c.Id == Bus_Return_Id select c).SingleOrDefault();
                    Upd.Passenger_number -= 1;
                }
                else
                {
                    if (Bus_Go_Id != null)
                    {
                        var Update = (from c in db.SRV_Bus where c.Id == Bus_Go_Id select c).SingleOrDefault();
                        Update.Passenger_number -= 1;
                    }
                    if (Bus_Return_Id != null)
                    {
                        var Upd = (from c in db.SRV_Bus where c.Id == Bus_Return_Id select c).SingleOrDefault();
                        Upd.Passenger_number -= 1;
                    }


                }
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public static bool Addstudent_to_bus_Temp(int student_Id, int? Bus_Go_Id, int? Station_Go_Id, int? Bus_Return_Id, int? Station_Return_Id, DateTime From, DateTime To)
        {
            try
            {

                SRV_BUS_Student_Temp Host = new SRV_BUS_Student_Temp();
                Host.Student_Id = student_Id;
                Host.Bus_Go_Id = Bus_Go_Id;
                Host.Station_Go_Id = Station_Go_Id;
                Host.Station_Return_Id = Station_Return_Id;
                Host.Bus_Return_Id = Bus_Return_Id;
                Host.Date = DateTime.Now;
                Host.From = From;
                Host.To = To;
                db.AddToSRV_BUS_Student_Temp(Host);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }
        }
        public static IEnumerable<SRV_Bus> GetBusByCode(string Code)
        {
            return (from d in db.SRV_Bus where d.Bus_Code == Code orderby d.Name select d);
        }
        public static IEnumerable<SRV_Bus> GetBusByName(string Name)
        {
            return (from d in db.SRV_Bus where d.Name == Name orderby d.Name select d);
        }
        public static long GetVoucherIdByorderid(int Payment_Order_Number)
        {
            return ((from d in db.ACC_Voucher where d.Payment_Order_Number == Payment_Order_Number select d.Number).FirstOrDefault());
        }
        public static IEnumerable<SRV_Bus_Station> GetStationByCode(string Code)
        {
            return (from d in db.SRV_Bus_Station where d.Sta_Code == Code orderby d.Name select d);
        }
        public static IEnumerable<SRV_Bus_Station> GetStationByName(string Name)
        {
            return (from d in db.SRV_Bus_Station where d.Name == Name orderby d.Name select d);
        }


        public static long Expen_ID(string screen)
        {

            var expenses = from x in db.ACC_Expenses_Screens where x.Screen_Id == (from y in db.SEC_Screen where y.Code == screen select y.Id).FirstOrDefault() select x;
            long e = expenses.FirstOrDefault().Expense_Id;
            return e;
        }
        public static IEnumerable<SRV_Bus_Price_Increase> ORDER_Discounts(int camp, int cert, int stag)
        {
            var q = from o in db.SRV_Bus_Price_Increase where o.Campus_Id == camp & o.Certificate_Id == cert && o.Stage_Id == stag select o;
            return q;

        }

        public static IEnumerable<SRV_Bus> GetBusByStation(long stationId)
        {
            return from x in db.SRV_Bus where db.SRV_Bus_Station_Price.Where(y => y.Station_Id == stationId).Select(y => y.Bus_Id).Contains(x.Id) select x;
        }

        //public static IEnumerable<voucher> Mysearch(Hashtable items)
        //{


        //}
    }
}
public class voucher
{

    public string FName { get; set; }
    public string SName { get; set; }
    public string TName { get; set; }
    public string FoName { get; set; }
    public long? bgoid { get; set; }
    public long? stgoid { get; set; }
    public long? bbackid { get; set; }
    public long? stbackid { get; set; }
    public string Bgo_Name { get; set; }
    public string Sgo_Name { get; set; }
    public string Bback_Name { get; set; }
    public string Sback_Name { get; set; }
    public long? Payment_order_num { get; set; }
    public long? Number { get; set; }
    public long? Student_Id { get; set; }

}